package com.gxa.service.cangkuservice.Impl;

import com.gxa.common.R;
import com.gxa.mapper.cangkumapper.ShangPinMapper;
import com.gxa.pojo.ShangPin;
import com.gxa.service.cangkuservice.ShangPinService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author zhl
 * @date 2022/4/2 16:15
 */
public class ShangPinServiceImpl implements ShangPinService {


    @Autowired
    public ShangPinMapper shangPinMapper;
    R r = new R();


    @Override
    public R selectAllShangPin() {

        List<ShangPin> shangpins = shangPinMapper.selectAllShangPin();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setCount(shangPinMapper.selectCountshangPin());
        r.setData(shangpins);
        return r;
    }

    @Override
    public R selectAllShangPinForPage(int page, int size) {
        r.setCode(200);
        r.setMsg("查询成功！");
        int index = (page - 1)*size;
        List<ShangPin> shangpins = shangPinMapper.selectAllShangPinForPage(index, size);
        r.setCount(shangPinMapper.selectCountshangPin());
        r.setData(shangpins);
        return r;
    }

    @Override
    public R selectShangPinByshangPinTypeOrshangPinBianHaoOrshangPinMingCheng(int page, int size, String shangPinType, String guiGeXingHao, String shangPinMingCheng, String unit, String shangPinBianHao) {
        r.setCode(200);
        r.setMsg("查询成功！");
        int index = (page - 1)*size;
        List<ShangPin> shangpins = shangPinMapper.selectShangPinByshangPinTypeOrshangPinBianHaoOrshangPinMingCheng
                (index,size,shangPinType,guiGeXingHao,shangPinMingCheng,unit,shangPinBianHao);
        r.setCount(shangPinMapper.selectCountshangPin());
        r.setData(shangpins);
        return r;
    }


}
